<?php

namespace CMS\Updater\Models;
/**
 * Trida entity sablony pro aktualizaci. 
 *
 * @author David Dusek
 */
use Doctrine\ORM\Mapping as ORM;

/** 
 * @ORM\Entity(repositoryClass="\CMS\Updater\Models\TemplateRepository")
 * @ORM\Table(name="updater_template")
 */
class Template extends \Nette\Object {
   /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue
     * @var int 
     */
    private $id;

    /**
     * @ORM\Column(length=100)
     * @var string 
     */
    private $name;        
    
    /**
     * @ORM\OneToMany(targetEntity="\CMS\Updater\Models\Domain", mappedBy="template")
     */
    private $domains;
    
    /**
     * @ORM\Column(name="svn_path", length=255)
     * @var string 
     */    
    private $svnPath;
    
    /**
     * @ORM\Column(name="svn_dir", length=255)
     * @var string 
     */    
    private $svnDir;
    
    /**
     * @ORM\Column(name="svn_name", length=50)
     * @var string 
     */
    private $svnName;
    
    /**
     * @ORM\Column(name="svn_pass", length=50)
     * @var string 
     */
    private $svnPass;
    
    /**
     * @ORM\Column(type="text")
     * @var string 
     */
    private $modules;
    
    public function __construct()
    {
        $this->domains = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    public function getId() {
        return $this->id;
    }
    
    public function setName($name) {
        $this->name = $name; 
    }

    public function getName() {
        return $this->name;
    }
    
    /* domains */
    public function addDomain(Domain $domain) {
        $this->domains->add($domains);
        $domain->setTemplate($this);
    }
    
    public function removeDomain(Domain $domain) {
        $this->domains->removeElement($domain);
        $domain->setTemplate(NULL);
    }
    
    public function getDomains() {
        return $this->domains;
    }
    
    public function getDomainsCount() {
        return $this->domains->count();
    }
    
    public function setSvnPath($svnPath) {
        $this->svnPath = $svnPath; 
    }

    public function getSvnPath() {
        return $this->svnPath;
    }
    
    public function setSvnDir($svnDir) {
        $this->svnDir = $svnDir; 
    }

    public function getSvnDir() {
        return $this->svnDir;
    }

    public function setSvnName($svnName) {
        $this->svnName = $svnName; 
    }

    public function getSvnName() {
        return $this->svnName;
    }

    public function setSvnPass($svnPass) {
        $this->svnPass = $svnPass; 
    }

    public function getSvnPass() {
        return $this->svnPass;
    }

    /**
     * Nastaveni aktualizovanych modulu.
     * @param array $modules 
     */
    public function setModules($modules) {
        $this->modules = implode(',', $modules);
    }

    /**
     * Ziskani seznamu vsech aktualizovanych modulu.
     * @return array 
     */
    public function getModules() {
        return explode(',', $this->modules);
    }

}
